#ifndef									__TCPCLIENT_H__
#define									__TCPCLIENT_H__

#include								<QObject>
#include								<map>
#include								"handler.h"
#include								"packet.h"
#include								"QtAsyncTcpSocket.h"

class									TcpClient : public QObject
{
		Q_OBJECT

public:
	TcpClient(PacketHandler *);
	~TcpClient();

public:

	quint16								addServer(const std::string &, const std::string &);
	void								sendPacket(Packet* pkg, quint16 id = 0);
	void								removeClient(quint16 id);

	QHostAddress 						getIp(quint16 id);
	quint16								getId(QHostAddress& ip);

	quint16								getUdpPort() const;
	quint16								getTcpPort() const;

	bool								isInside(quint16 id);
	bool								isInside(QHostAddress& ip);

	void								initConnect(QtAsyncTcpSocket &socket);

private:
	std::map<quint16,QtAsyncTcpSocket*>	_sockets;
	PacketHandler						*_packet;
	quint16								_lastId;

public slots:
	void								handleConnect(QHostAddress &);
	void								handleDisconnect(QHostAddress &);

signals:
	void								connected(QHostAddress &);
	void								disconnected(QHostAddress &);
};

#endif								//!__TCPCLIENT_H__